﻿using System;
using System.Collections.Generic;
using System.Text;
using SerializationHelperLib;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace ConfigMgmtEx
{
    public class ConfigHash : XmlSerializableDictionary<string, ConfigEntry>
    {
        public new void Add(string key, ConfigEntry ce)
        {
            base.Add(key, ce);
        }

        public void Add(string key, object o)
        {
            ConfigEntry ce = new ConfigEntry(o);
            base.Add(key, ce);
        }

        public void SaveAsXml(string fileName)
        {
            XmlSerializer ser = new XmlSerializer(typeof(ConfigHash));
            using (TextWriter tw = new StreamWriter(fileName))
            {
                ser.Serialize(tw, this);
            }

        }

        public static ConfigHash CreateFromXml(string fileName)
        {
            ConfigHash o = new ConfigHash();
            XmlSerializer ser = new XmlSerializer(typeof(ConfigHash));
            using (TextReader tr = new StreamReader(fileName))
            {
                o = (ConfigHash)ser.Deserialize(tr);
            }
            return o;
        }
    }
}
